package com.cskaoyan.catmall.controller.wx;

import com.cskaoyan.catmall.model.bo.WxAddOrDeleteBo;
import com.cskaoyan.catmall.model.bo.WxCollectListBo;
import com.cskaoyan.catmall.model.pojo.MarketUser;
import com.cskaoyan.catmall.model.vo.BaseRespVo;
import com.cskaoyan.catmall.model.vo.WxCollectListVo;
import com.cskaoyan.catmall.service.WxCollectService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 创建日期: 2022/01/10 14:24
 *
 * @author WangZhe
 * 备注:
 */
@RestController
@RequestMapping("wx/collect")
public class WxCollectController {

    @Autowired
    WxCollectService wxCollectService;

    @GetMapping("list")
    public BaseRespVo getList(WxCollectListBo wxCollectListBo) {

//        Integer userId = 1;
        MarketUser user = (MarketUser) SecurityUtils.getSubject().getPrincipal();
        Integer userId = user.getId();

        WxCollectListVo vo = wxCollectService.getList(userId, wxCollectListBo);
        return BaseRespVo.ok(vo);
    }

    @PostMapping("addordelete")
    public BaseRespVo addOrDelete(@RequestBody WxAddOrDeleteBo wxAddOrDeleteBo) {

//        Integer userId = 1;
        MarketUser user = (MarketUser) SecurityUtils.getSubject().getPrincipal();
        Integer userId = user.getId();

        wxCollectService.addOrDelete(userId, wxAddOrDeleteBo);
        return BaseRespVo.ok();
    }
}
